/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package drt;

import java.util.LinkedHashSet;
import java.util.Map;
import logic.Type;

/**
 *
 * @author phong
 */
public class DRSInworldCondition extends DRSUnaryComplexCondition {
    
    DRSReferent ref;
    
    public DRSInworldCondition(DrtExpression term, DRSReferent ref) {
        super(term);
        this.ref = ref;
    }
    
    public DRSReferent getRef() {
        return this.ref;
    }
    
    @Override
    public Type getType() {
        return Type.UNKNOWN_TYPE;
    }
    
    /*
     * we do not solve the double negated DRS
     * (it is not true that -(-DRS) = DRS
     */
    @Override
    public DRSInworldCondition simplify() {
        return new DRSInworldCondition(this.term.simplify(), this.ref);
    }
    
    @Override
    public DRSInworldCondition replace(DrtVariable var, DrtExpression exp) {
        return new DRSInworldCondition(this.term.replace(var, exp), this.ref.replace(var, exp));
    }
    
    @Override
    public String toString() {
        return this.ref.toString() + ":" + this.term.toString();
    }
    
    @Override
    public boolean equals(Object other) {
        if (other instanceof DRSInworldCondition) {
            return this.term.equals(((DRSInworldCondition)other).term) && 
                    this.ref.equals(((DRSInworldCondition)other).ref);
        }
        return false;
    }
    
    @Override
    public void getRefs(LinkedHashSet<DRSReferent> refs) {
        refs.add(this.ref);
        super.getRefs(refs);
    }
    
    @Override
    public void getAllVariables(LinkedHashSet<DrtVariable> vars) {
        vars.add(this.ref);
        super.getAllVariables(vars);
    }

    @Override
    public DRSInworldCondition getTemplate(Map<String,String> map) {
        DrtExpression newTerm = this.term.getTemplate(map);
        return new DRSInworldCondition(newTerm, ref);
    }
}
